.TH "KYSDK_SKIPLIST_SEARCH" 3 "Fri Sep 22 2023" "My Project" \" -*- nroff -*-
.ad l
.nh
.SH NAME
kysdk_skiplist_search \- 根据给定的key搜索data内容  

.SH SYNOPSIS
br
.PP
\fC#include <skip_linklist\&.h>\fP
.br

.SS "Functions"
.SS "kysdk_listdata kysdk_skiplist_search (\fBkysdk_skiplist\fP * list, int key)"

.PP
根据给定的key搜索data内容 
.PP
\fBParameters\fP
.RS 4
\fIlist\fP 需要操作的链表 
.br
\fIkey\fP 键 
.RE
.PP
\fBReturns\fP
.RS 4
kysdk_listdata， 当搜索的key不存在时，data\&.num值为-1 

\fBtypedef union _kysdk_listdata {
.br
    void *ptr;
    int num;
.br
} kysdk_listdata;\fP
.RE
.PP
Link with \fI\-lkydatastruct\fP.
.SH "Detailed Description"
.PP 
接口的主要功能是根据给定的key搜索data内容
.SH EXAMPLES
.EX
#include <skip_linklist.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>

#define ARRAY_SIZE    20

int array[ARRAY_SIZE];
int del_flag[ARRAY_SIZE] = {0};

void print_list(kysdk_skiplist *list)
{
    for (int i = list->max_levels - 1; i >= 0; i --)
    {
        kysdk_skiplist_node *curnode = list->children[i];
        printf("Level[%d]: ", i);
        while (curnode)
        {
            printf("%d->", curnode->key);
            curnode = curnode->next[i];
        }
        printf("NULL\n");
    }
}

int test_list_delete(kysdk_skiplist *list)
{
    for (int i = 0; i < ARRAY_SIZE; i ++)
    {
        if (random() % 2)
        {
            del_flag[i] = 1;
            kysdk_skiplist_delete(list, array[i]);
            printf("Deleted %d\n", array[i]);
        }
    }

    for (int i = 0; i < ARRAY_SIZE; i ++)
    {
        if (del_flag[i] && kysdk_skiplist_search(list, array[i]).num != -1)
        {
            printf("Skiplist delete test failed.\n");
            return -1;
        }
    }

    printf("Skiplist order test pass.\n");

    return 0;
}

int main()
{
    kysdk_skiplist *list = kysdk_create_skiplist();

    kysdk_skiplist_setmaxlevels(list, 5);
    
    srand(time(NULL));

    for (int i = 0; i < ARRAY_SIZE; i ++)
    {
        array[i] = i;
        kysdk_skiplist_insert(list, i, (kysdk_listdata)i);
        printf("%d has been insert.\n", i);
        sleep(1);
    }
    
    print_list(list);

    int res = test_list_delete(list);

    print_list(list);

    kysdk_destroy_skiplist(list);

    return res;
}
.SH "CONFORMING TO"
These functions are as per the withdrawn POSIX.1e draft specification.
The following functions are Linux extensions:
.BR kysdk_create_skiplist (),
.BR kysdk_destroy_skiplist (),
.BR kysdk_skiplist_setmaxlevels (),
.BR kysdk_skiplist_insert ()
and
.BR kysdk_skiplist_delete ().
.SH "SEE ALSO"
.BR kysdk_create_skiplist (3),
.BR kysdk_destroy_skiplist (3),
.BR kysdk_skiplist_setmaxlevels (3),
.BR kysdk_skiplist_insert (3)
and
.BR kysdk_skiplist_delete (3).

.SH "Author"
.PP 
Generated automatically by Doxygen for skip_linklist.h  from the source code\&.
